<?php
/**
 *	[alias(alias.{modulename})] (C)2012-2099 Powered by abans@qq.com.
 *	Version: v1.0
 *	Date: 2012-10-17 09:40
 */
//error_reporting(E_ALL);
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
loadcache('plugin');
if(!defined('Adz_class')){include('source/plugin/alias/Adz.class.php');}
if(!defined('Adz_alias_fun')) include('alias.fun.php');
Adz::auth('alias');//判断权限
$Acan_ui = Adz::acan_ui('push');
$aconfig = $_G['cache']['plugin']['alias'];
$aconfigjson = json_encode($aconfig);
$Adomain = array('forum'=>subdomain('forum'));
$Adomainjson = json_encode($Adomain);
if(defined('MAGIC_QUOTES_GPC') && MAGIC_QUOTES_GPC == false){
	$_GET = daddslashes($_GET);
	$_POST = daddslashes($_POST);
}
if($_POST['save']){
	if(!submitcheck('save',1)){echo -1;exit;}
	$save = $_POST['save'];
	$alias_id = $save['id'];
	unset($save['id']);
	if(CHARSET=='gbk' || CHARSET=='big5'){
		if(function_exists('mb_convert_encoding')){
			$save['alias'] = mb_convert_encoding($save['alias'],CHARSET,'utf-8');
			$save['alias'] = str_replace('?','',$save['alias']);
		}elseif(CHARSET=='gbk'){
			$save['alias'] = iconv('utf-8',CHARSET,$save['alias']);
		}
	}
	$rs = Adz::fetch_con('plugin_alias_bind',array('id'=>$alias_id));
	if($rs) $ars = Adz::mysql_save('plugin_alias_bind',$save,array('id'=>$alias_id));
	print_r($ars);
	exit;
}
if($_POST['act']=='del'){
	$ids = $_POST['ids'];
	if(!submitcheck('ids',1)){echo -1;exit;}
	$ars = DB::delete('plugin_alias_bind','id IN ('.$ids.')');
	print_r($ars);
	exit;
}

$_G['setting']['memberperpage'] = 20;
$page = max(1, $_G['page']);
$start_limit = ($page - 1) * $_G['setting']['memberperpage'];
$Asearch = array_merge($_GET, $_POST);
$soprr = array(
	'alias'=>lang('plugin/alias','alias'),
	'tid'=>lang('plugin/alias','tid').'ID',
	'subject'=>lang('plugin/alias','subject'),
	'author'=>lang('plugin/alias','author'),
	'authorid'=>lang('plugin/alias','author').'UID',
);

if($Asearch['keys']) {
	$con = $Asearch['sop'].' LIKE \''.str_replace('*','%',$Asearch['keys']).'\'';
}
$otherurl = "forum.php?mod=modcp&action=plugin&op=base&id=alias:list";
if($search['keys']){
	$otherurl .= '&keys='.$search['keys'];
}
if($search['sop']){
	$otherurl .= '&sop='.$search['sop'];
}
$member = array();
$tableext = '';
$crs = Adz::fetch_con('plugin_alias_bind',$con,'count(id) as num');
$membernum = $crs['num'];
if($crs['num'] > 0) {
	$multipage = multi($crs['num'], $_G['setting']['memberperpage'], $page, $otherurl.$urladd);
	if($con) $where = 'and '.$con;
	$sql = 'SELECT a.*,t.author,t.authorid,t.subject,t.views,t.dateline,t.lastpost FROM '.DB::table('plugin_alias_bind').' a LEFT JOIN '.DB::table('forum_thread').' t ON t.tid=a.rid WHERE 1 '.$where.' LIMIT '.$start_limit.','.$_G['setting']['memberperpage'];
	$data = Adz::fetch_all($sql);
	foreach ($data as $k => $v) {
		$data[$k]['url'] = str_replace('{alias}',$v['alias'],$aconfig['fm_tid']);
	}
}
